package com.gedi.data.OutPutFormate;


import org.apache.hadoop.mapreduce.lib.db.DBWritable;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author:RenPu
 * @Date: 2020/1/16 15:02
 * @Version: 1.0
 * @description:
 */
public class WordWritable implements DBWritable {

    private String word;
    private Integer wordCount;

    public WordWritable() {
    }

    public WordWritable(String word, Integer wordCount) {
        this.word = word;
        this.wordCount = wordCount;
    }

    public String getWord() {
        return word;
    }

    public void setWord(String word) {
        this.word = word;
    }

    public Integer getWordCount() {
        return wordCount;
    }

    public void setWordCount(Integer wordCount) {
        this.wordCount = wordCount;
    }

    public void write(PreparedStatement preparedStatement) throws SQLException {

        //设置表设计时字段的行数与实体属性进行映射；
        preparedStatement.setString(2,this.word);
        preparedStatement.setInt(1,this.wordCount);
    }

    public void readFields(ResultSet resultSet) throws SQLException {

        //设置与库表字段对应的映射
        this.word=resultSet.getString("word");
        this.wordCount=resultSet.getInt("word_count");
    }
}
